package lk.icta.core.web.action;

import lk.icta.common.dto.WorkBenchItem;
import lk.icta.common.web.action.BaseAction;
import lk.icta.core.entity.LandApplication;
import lk.icta.core.service.LandApplicationManagementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * @author Mahesha Kalpanie
 */
public class ApplicationAction extends BaseAction {
    private static final Logger logger = LoggerFactory.getLogger(ApplicationAction.class);
    private final LandApplicationManagementService landApplicationManagementService;

    private List<WorkBenchItem> workBenchItemList;
    private List<LandApplication> landApplicationList;
    private long applicationId;
    private int editMode;
    private String workflowAction;

    public ApplicationAction(LandApplicationManagementService landApplicationManagementService) {
        this.landApplicationManagementService = landApplicationManagementService;
    }

    public String completeApplication() {
        logger.debug("Complete Land Application : {} ", user.getUsername());

        landApplicationManagementService.completeLandApplication(applicationId, user);
        return SUCCESS;
    }

    public String loadListToBeCompleted() {
        try {
            logger.debug("Complete Land Application list to be completed : {}", user.getUsername());
            landApplicationList = landApplicationManagementService.getApplicationsToBeCompleted(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }



    /*
private List<LandApplication> findAppListToBeApproved(WorkflowTask currentState,
    WorkflowTask nextState) {
    logger.debug("Find Land Application List to be approved : {} ", user.getUsername());
    List<LandApplication> landApplications =
        landApplicationManagementService.getApplicationsByWorkflowState(user, currentState);
    List<LandApplication> landAppsToBeApproved = new ArrayList<LandApplication>();
    for (LandApplication landApp : landApplications) {
        if (landApp.getPreferredAlienationMethod().getWorkflow1().contains(nextState)) {
            landAppsToBeApproved.add(landApp);
        }
    }
    return landAppsToBeApproved;
}    */

    public List<WorkBenchItem> getWorkBenchItemList() {
        return workBenchItemList;
    }

    public void setWorkBenchItemList(List<WorkBenchItem> workBenchItemList) {
        this.workBenchItemList = workBenchItemList;
    }

    public List<LandApplication> getLandApplicationList() {
        return landApplicationList;
    }

    public void setLandApplicationList(List<LandApplication> landApplicationList) {
        this.landApplicationList = landApplicationList;
    }

    public long getApplicationId() {
        return applicationId;
    }

    public void setApplicationId(long applicationId) {
        this.applicationId = applicationId;
    }

    public int getEditMode() {
        return editMode;
    }

    public void setEditMode(int editMode) {
        this.editMode = editMode;
    }

    public String getWorkflowAction() {
        return workflowAction;
    }

    public void setWorkflowAction(String workflowAction) {
        this.workflowAction = workflowAction;
    }
}
